package com.ego.item.web;

import com.ego.item.pojo.Specification;
import com.ego.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spec")
public class SpecificationController {
    @Autowired
    private SpecificationService specificationService;
    @PostMapping
    public ResponseEntity<Void> save(Specification specification){
         specificationService.save(specification);
         return  ResponseEntity.ok().build();
    }
    @GetMapping("/{cid}")
    public ResponseEntity<String> queryByCid(@PathVariable("cid") Long cid){
        Specification result=specificationService.findByCid(cid);
        if(result==null){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result.getSpecifications());
    }
    @PutMapping
    public ResponseEntity<Void> put(Specification specification){
        specificationService.put(specification);
        return  ResponseEntity.ok().build();
    }
}
